<?php
defined('SYSPATH') OR die('No direct access allowed.');
/**
 * main.php
 * @author ranuandra
 *
 * 15 Agu 2011 14:42:09
 *
 * 
 */
?>
/*!
 * Ext JS Library 3.2.1
 * Copyright(c) 2006-2010 Ext JS, Inc.
 * licensing@extjs.com
 * http://www.extjs.com/license
 */

// Sample desktop configuration
MyDesktop = new Ext.app.App({
	init :function(){
		Ext.QuickTips.init();
	},

	getModules : function(){
		return [
			//new MyDesktop.MaterialWindow(),
			//new MyDesktop.SupplierWindow(),
			//new MyDesktop.LocationWindow(),
			//new MyDesktop.MaterialinWindow(),
			new MyDesktop.MasterMenuModule(),
			new MyDesktop.MaterialinMenuModule(),
			new MyDesktop.MaterialoutMenuModule(),
			//new MyDesktop.DailyreportWindow(),
			//new MyDesktop.groupWindow(),
			new MyDesktop.ReportMenuModule(),
			new MyDesktop.UserWindow()
            //new MyDesktop.TabWindow(),
            //new MyDesktop.AccordionWindow(),
            //new MyDesktop.BogusMenuModule(),
            //new MyDesktop.BogusModule()
		];
	},

    // config for the start menu
    getStartConfig : function(){
        return {
            title: 'User',
            iconCls: 'user',
            toolItems: [{
                text:'User',
                iconCls:'user',
                handler: this.UserWindow,
                scope:this
            },'-',{
                text:'Logout',
                iconCls:'logout',
                handler: this.createWindow,
                scope:this
                
            }]
        };

    },

    UserWindow : function()
    {
    	var user = new MyDesktop.UserWindow();
    }

    
});



/*
 * Example windows
 */
MyDesktop.GridWindow = Ext.extend(Ext.app.Module, {
    id:'grid-win',
    init : function(){
        this.launcher = {
            text: 'Grid Window',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('grid-win');
        if(!win){
            win = desktop.createWindow({
                id: 'grid-win',
                title:'Grid Window',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items:
                    new Ext.grid.GridPanel({
                        border:false,
                        ds: new Ext.data.Store({
                            reader: new Ext.data.ArrayReader({}, [
                               {name: 'company'},
                               {name: 'price', type: 'float'},
                               {name: 'change', type: 'float'},
                               {name: 'pctChange', type: 'float'}
                            ]),
                            data: Ext.grid.dummyData
                        }),
                        cm: new Ext.grid.ColumnModel([
                            new Ext.grid.RowNumberer(),
                            {header: "Company", width: 120, sortable: true, dataIndex: 'company'},
                            {header: "Price", width: 70, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
                            {header: "Change", width: 70, sortable: true, dataIndex: 'change'},
                            {header: "% Change", width: 70, sortable: true, dataIndex: 'pctChange'}
                        ]),

                        viewConfig: {
                            forceFit:true
                        },
                        //autoExpandColumn:'company',

                        tbar:[{
                            text:'Add Something',
                            tooltip:'Add a new row',
                            iconCls:'add'
                        }, '-', {
                            text:'Options',
                            tooltip:'Blah blah blah blaht',
                            iconCls:'option'
                        },'-',{
                            text:'Remove Something',
                            tooltip:'Remove the selected item',
                            iconCls:'remove'
                        }]
                    })
            });
        }
        win.show();
    }
});

//user
MyDesktop.UserWindow = Ext.extend(Ext.app.Module, {
    id:'grid-material',
    init : function(){
        this.launcher = {
            text: 'Material',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('grid-material');
        if(!win){
        	var MaterialGrid = new App.material.Grid();
            win = desktop.createWindow({
                id: 'grid-material',
                title:'Material',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [MaterialGrid]
            });
        }
        win.show();
    }
});



//material
MyDesktop.MaterialWindow = Ext.extend(Ext.app.Module, {
    id:'grid-material',
    init : function(){
        this.launcher = {
            text: 'Material',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('grid-material');
        if(!win){
        	var MaterialGrid = new App.material.Grid();
            win = desktop.createWindow({
                id: 'grid-material',
                title:'Material',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [MaterialGrid]
            });
        }
        win.show();
    }
});

//supplier
MyDesktop.SupplierWindow = Ext.extend(Ext.app.Module, {
    id:'supplier-win',
    init : function(){
        this.launcher = {
            text: 'Supplier',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('supplier-win');
        if(!win){
        	var SupplierGrid = new App.supplier.Grid();
            win = desktop.createWindow({
                id: 'supplier-win',
                title:'Supplier',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [SupplierGrid]
            });
        }
        win.show();
    }
});

MyDesktop.MaterialinWindow = Ext.extend(Ext.app.Module, {
    id:'materialin-win',
    init : function(){
        this.launcher = {
            text: 'Material In',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('materialin-win');
        var MaterialinGrid = new App.materialin.Grid();
        if(!win){
        	//var MaterialinGrid = new App.materialin.Grid();
            var supplierStore = new Ext.data.JsonStore({
                url           : '<?php echo URL::base()?>supplier/view',
                root          : 'supplier',
                totalProperty : 'total',
                id            : 'id',
                fields        : ['id', 'name'],
                remoteSort    : true,
                autoload      : true
            });

            supplierStore.load();   
            
            var locationStore = new Ext.data.JsonStore({
                url           : '<?php echo URL::base()?>location/view',
                root          : 'location',
                totalProperty : 'total',
                id            : 'id',
                fields        : ['id', 'name'],
                remoteSort    : true,
                autoload      : true
            });

            locationStore.load();   

            var frmPanel = new Ext.FormPanel({
    	   	 	url         : '<?php echo URL::base()?>materialin/save',
    	        labelAlign: 'top',
    	        bodyStyle:'padding:5px',
    	        width:740,
    	        items: [{
    	            layout:'column',
    	            border:false,
    	            items:[{
    	                columnWidth:.5,
    	                layout: 'form',
    	                border:false,
    	                items: [{
    	                    xtype:'datefield',
    	                    fieldLabel: 'Tanggal',
    	                    name: 'tgl',
    	                    anchor:'95%',
    	                    format: 'd/m/Y',
    	                    value: new Date()
    	                },{
    	                    xtype:'textfield',
    	                    fieldLabel: 'No Order',
    	                    name: 'no_order',
    	                    anchor:'95%'
    	                },{
    	                    xtype:'textfield',
    	                    fieldLabel: 'No Container',
    	                    name: 'truck_number',
    	                    anchor:'95%'
    	                }]
    	            },{
    	                columnWidth:.5,
    	                layout: 'form',
    	                border:false,
    	                items: [{
    						fieldLabel 		: 'Supplier',
    						xtype	   		: 'combo',	
    						store			: supplierStore,
    						typeAhead		: true,
    						editable		: true,
    						mode			: 'local',
    						triggerAction	: 'all',
    						selectOnFocus	: true,
    						displayField	: 'name',
                			valueField		: 'id', 
                			name	   		: 'supplier_id',	
                			hiddenName 		: 'supplier_id',
                			anchor:'95%'
    	                }, {
    						fieldLabel 		: 'Location',
    						xtype	   		: 'combo',	
    						store			: locationStore,
    						typeAhead		: true,
    						editable		: true,
    						mode			: 'local',
    						triggerAction	: 'all',
    						selectOnFocus	: true,
    						displayField	: 'name',
                			valueField		: 'id', 
                			name	   		: 'location_id',	
                			hiddenName 		: 'location_id',
                			anchor:'95%'
    	                }]
    	            }]
    	        },{
    	            xtype:'panel',
    	            plain:true,

    	            deferredRender: false,
    	            defaults:{bodyStyle:'padding:10px'},
    	            items:[ MaterialinGrid]
    	        }],
    	        buttons: [{
    	            text: 'Save',
                	formBind : true,
                	iconCls: 'icon-save',
    	            handler  : function(){
    	              var dstore = MaterialinGrid.store;
					  var data_array = [];
					  dstore .each(function(dstore ){
						        data_array.push(dstore .data);
					  });
					  data_array = Ext.util.JSON.encode(data_array);
					 		
    	        	frmPanel.getForm().submit({
    	        	
    	                    method    : 'POST',
    	                    waitTitle : 'Processing',
    	                    waitMsg   : 'Please Wait',
    	                    params	  : {material:data_array },
    	                    success   : function (form, action) {
    	                    	Ext.Msg.alert('Sukses!', action.result.message);
    	                    	//store.reload();
    	                    	//addAnggotaWin.close();
    	                    },
    	                    failure   : function (form, action) {
    	                        if (action.failureType === 'server') {
    	                            //obj = Ext.util.JSON.decode(action.response.responseText).data;
    	                            Ext.Msg.alert('Process Failed!', action.result.error);
    	                        } else {
    	                            //obj = Ext.util.JSON.decode(action.response.responseText);
    	                            Ext.Msg.alert('Warning!', action.result.error);
    	                        }
    	                    }
    	                });
    	              
    	               
    	                //MaterialinGrid.store.save();
    	                
    	            }
    	        }]
    	        
    	    });
    	    
            win = desktop.createWindow({
                id: 'materialin-win',
                title:'Materil In',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [frmPanel]
            });
        }
        win.show();
    }
});

MyDesktop.MaterialoutWindow = Ext.extend(Ext.app.Module, {
    id:'materialin-win',
    init : function(){
        this.launcher = {
            text: 'Material out',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('materialout-win');
        var MaterialoutGrid = new App.materiaout.Grid({
        	id: 0
        });
        if(!win){   
            
            var locationStore = new Ext.data.JsonStore({
                url           : '<?php echo URL::base()?>location/view',
                root          : 'location',
                totalProperty : 'total',
                id            : 'id',
                fields        : ['id', 'name'],
                remoteSort    : true,
                autoload      : true
            });

            locationStore.load();   

            var frmPanel = new Ext.FormPanel({
    	   	 	url         : '<?php echo URL::base()?>materialout/save',
    	        labelAlign: 'top',
    	        bodyStyle:'padding:5px',
    	        width:740,
    	        items: [{
    	            layout:'column',
    	            border:false,
    	            items:[{
    	                columnWidth:.5,
    	                layout: 'form',
    	                border:false,
    	                items: [{
    	                    xtype:'datefield',
    	                    fieldLabel: 'Tanggal',
    	                    name: 'tgl',
    	                    anchor:'95%',
    	                    format: 'd/m/Y',
    	                    value: new Date()
    	                },{
    	                    xtype:'textfield',
    	                    fieldLabel: 'No Order',
    	                    name: 'no_order',
    	                    anchor:'95%'
    	                }]
    	            }]
    	        },{
    	            xtype:'panel',
    	            plain:true,

    	            deferredRender: false,
    	            defaults:{bodyStyle:'padding:10px'},
    	            items:[ MaterialoutGrid]
    	        }],
    	        buttons: [{
    	            text: 'Save',
                	formBind : true,
                	iconCls: 'icon-save',
    	            handler  : function(){
    	              var dstore = Materialout.store;
					  var data_array = [];
					  dstore .each(function(dstore ){
						        data_array.push(dstore .data);
					  });
					  data_array = Ext.util.JSON.encode(data_array);
					 		
    	        	frmPanel.getForm().submit({
    	        	
    	                    method    : 'POST',
    	                    waitTitle : 'Processing',
    	                    waitMsg   : 'Please Wait',
    	                    params	  : {material:data_array },
    	                    success   : function (form, action) {
    	                    	Ext.Msg.alert('Sukses!', action.result.message);
    	                    	//store.reload();
    	                    	//addAnggotaWin.close();
    	                    },
    	                    failure   : function (form, action) {
    	                        if (action.failureType === 'server') {
    	                            //obj = Ext.util.JSON.decode(action.response.responseText).data;
    	                            Ext.Msg.alert('Process Failed!', action.result.error);
    	                        } else {
    	                            //obj = Ext.util.JSON.decode(action.response.responseText);
    	                            Ext.Msg.alert('Warning!', action.result.error);
    	                        }
    	                    }
    	                });
    	              
    	               
    	                //MaterialinGrid.store.save();
    	                
    	            }
    	        }]
    	        
    	    });
    	    
            win = desktop.createWindow({
                id: 'materialout-win',
                title:'Material Out',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [frmPanel]
            });
        }
        win.show();
    }
});

//location
MyDesktop.LocationWindow = Ext.extend(Ext.app.Module, {
    id:'location-win',
    init : function(){
        this.launcher = {
            text: 'Location',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('location-win');
        if(!win){
        	var LocationGrid = new App.location.Grid();
            win = desktop.createWindow({
                id: 'location-win',
                title:'Location',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [LocationGrid]
            });
        }
        win.show();
    }
});


//group
MyDesktop.groupWindow = Ext.extend(Ext.app.Module, {
    id:'group-win',
    init : function(){
        this.launcher = {
            text: 'Group',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('group-win');
        if(!win){
        	var groupGrid = new App.group.Grid();
            win = desktop.createWindow({
                id: 'group-win',
                title:'Group',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [groupGrid]
            });
        }
        win.show();
    }
});

MyDesktop.TabWindow = Ext.extend(Ext.app.Module, {
    id:'tab-win',
    init : function(){
        this.launcher = {
            text: 'Tab Window',
            iconCls:'tabs',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('tab-win');
        if(!win){
            win = desktop.createWindow({
                id: 'tab-win',
                title:'Tab Window',
                width:740,
                height:480,
                iconCls: 'tabs',
                shim:false,
                animCollapse:false,
                border:false,
                constrainHeader:true,

                layout: 'fit',
                items:
                    new Ext.TabPanel({
                        activeTab:0,

                        items: [{
                            title: 'Tab Text 1',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 2',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 3',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 4',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        }]
                    })
            });
        }
        win.show();
    }
});



MyDesktop.AccordionWindow = Ext.extend(Ext.app.Module, {
    id:'acc-win',
    init : function(){
        this.launcher = {
            text: 'Accordion Window',
            iconCls:'accordion',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('acc-win');
        if(!win){
            win = desktop.createWindow({
                id: 'acc-win',
                title: 'Accordion Window',
                width:250,
                height:400,
                iconCls: 'accordion',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                tbar:[{
                    tooltip:{title:'Rich Tooltips', text:'Let your users know what they can do!'},
                    iconCls:'connect'
                },'-',{
                    tooltip:'Add a new user',
                    iconCls:'user-add'
                },' ',{
                    tooltip:'Remove the selected user',
                    iconCls:'user-delete'
                }],

                layout:'accordion',
                border:false,
                layoutConfig: {
                    animate:false
                },

                items: [
                    new Ext.tree.TreePanel({
                        id:'im-tree',
                        title: 'Online Users',
                        loader: new Ext.tree.TreeLoader(),
                        rootVisible:false,
                        lines:false,
                        autoScroll:true,
                        tools:[{
                            id:'refresh',
                            on:{
                                click: function(){
                                    var tree = Ext.getCmp('im-tree');
                                    tree.body.mask('Loading', 'x-mask-loading');
                                    tree.root.reload();
                                    tree.root.collapse(true, false);
                                    setTimeout(function(){ // mimic a server call
                                        tree.body.unmask();
                                        tree.root.expand(true, true);
                                    }, 1000);
                                }
                            }
                        }],
                        root: new Ext.tree.AsyncTreeNode({
                            text:'Online',
                            children:[{
                                text:'Friends',
                                expanded:true,
                                children:[{
                                    text:'Jack',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Brian',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Jon',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Tim',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Nige',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Fred',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Bob',
                                    iconCls:'user',
                                    leaf:true
                                }]
                            },{
                                text:'Family',
                                expanded:true,
                                children:[{
                                    text:'Kelly',
                                    iconCls:'user-girl',
                                    leaf:true
                                },{
                                    text:'Sara',
                                    iconCls:'user-girl',
                                    leaf:true
                                },{
                                    text:'Zack',
                                    iconCls:'user-kid',
                                    leaf:true
                                },{
                                    text:'John',
                                    iconCls:'user-kid',
                                    leaf:true
                                }]
                            }]
                        })
                    }), {
                        title: 'Settings',
                        html:'<p>Something useful would be in here.</p>',
                        autoScroll:true
                    },{
                        title: 'Even More Stuff',
                        html : '<p>Something useful would be in here.</p>'
                    },{
                        title: 'My Stuff',
                        html : '<p>Something useful would be in here.</p>'
                    }
                ]
            });
        }
        win.show();
    }
});

// for example purposes
var windowIndex = 0;

MyDesktop.BogusModule = Ext.extend(Ext.app.Module, {
    init : function(){
        this.launcher = {
            text: 'Window '+(++windowIndex),
            iconCls:'bogus',
            handler : this.createWindow,
            scope: this,
            windowId:windowIndex
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('bogus'+src.windowId);
        if(!win){
            win = desktop.createWindow({
                id: 'bogus'+src.windowId,
                title:src.text,
                width:640,
                height:480,
                html : '<p>Something useful would be in here.</p>',
                iconCls: 'bogus',
                shim:false,
                animCollapse:false,
                constrainHeader:true
            });
        }
        win.show();
    }
});


MyDesktop.MasterMenuModule = Ext.extend(Ext.app.Module, {
    init : function(){
        this.launcher = {
            text: 'Master',
            iconCls: 'bogus',
            handler: function() {
				return false;
			},
            menu: {
                items:[{
                    text: 'Material',
                    iconCls:'bogus',
                    handler : this.createMaterialWindow,
                    scope: this,
                    windowId: 'grid-material'
                    },{
                    text: 'Supplier',
                    iconCls:'bogus',
                    handler : this.createSupplierWindow,
                    scope: this,
                    windowId: 'supplier-win'
                    },{
                    text: 'Location',
                    iconCls:'bogus',
                    handler : this.createLocationWindow,
                    scope: this,
                    windowId: 'Location-win'
                    },{
                    text: 'Group',
                    iconCls:'bogus',
                    handler : this.createGroupWindow,
                    scope: this,
                    windowId: 'group-win'
                    }]
            }
        }
    },
    
   createMaterialWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('grid-material');
        if(!win){
        	var MaterialGrid = new App.material.Grid();
            win = desktop.createWindow({
                id: 'grid-material',
                title:'Material',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [MaterialGrid]
            });
        }
        win.show();
    },
    
    createSupplierWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('supplier-win');
        if(!win){
        	var SupplierGrid = new App.supplier.Grid();
            win = desktop.createWindow({
                id: 'supplier-win',
                title:'Supplier',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [SupplierGrid]
            });
        }
        win.show();
    },
    
    createLocationWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('location-win');
        if(!win){
        	var LocationGrid = new App.location.Grid();
            win = desktop.createWindow({
                id: 'location-win',
                title:'Location',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [LocationGrid]
            });
        }
        win.show();
    },
    
    createGroupWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('group-win');
        if(!win){
        	var groupGrid = new App.group.Grid();
            win = desktop.createWindow({
                id: 'group-win',
                title:'Group',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [groupGrid]
            });
        }
        win.show();
    }
});


MyDesktop.MaterialinMenuModule = Ext.extend(Ext.app.Module, {
    init : function(){
        this.launcher = {
            text: 'Material In',
            iconCls: 'bogus',
            handler: function() {
				return false;
			},
            menu: {
                items:[{
                    text: 'Form Material In',
                    iconCls:'bogus',
                    handler : this.createFormWindow,
                    scope: this,
                    windowId: 'materialin-win'
                    },{
                    text: 'Data Material In',
                    iconCls:'bogus',
                    handler : this.createDataWindow,
                    scope: this,
                    windowId: 'supplier-win'
                    }]
            }
        }
    },
    
	createFormWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('materialin-win');
        var MaterialinGrid = new App.materialin.Grid();
        if(!win){
        	//var MaterialinGrid = new App.materialin.Grid();
            var supplierStore = new Ext.data.JsonStore({
                url           : '<?php echo URL::base()?>supplier/view',
                root          : 'supplier',
                totalProperty : 'total',
                id            : 'id',
                fields        : ['id', 'name'],
                remoteSort    : true,
                autoload      : true
            });

            supplierStore.load();   
            
            var locationStore = new Ext.data.JsonStore({
                url           : '<?php echo URL::base()?>location/view',
                root          : 'location',
                totalProperty : 'total',
                id            : 'id',
                fields        : ['id', 'name'],
                remoteSort    : true,
                autoload      : true
            });

            locationStore.load();   

            var frmPanel = new Ext.FormPanel({
    	   	 	url         : '<?php echo URL::base()?>materialin/save',
    	        labelAlign: 'top',
    	        bodyStyle:'padding:5px',
    	        width:740,
    	        items: [{
    	            layout:'column',
    	            border:false,
    	            items:[{
    	                columnWidth:.5,
    	                layout: 'form',
    	                border:false,
    	                items: [{
    	                    xtype:'datefield',
    	                    fieldLabel: 'Tanggal',
    	                    name: 'tgl',
    	                    anchor:'95%',
    	                    format: 'd/m/Y',
    	                    value: new Date()
    	                },{
    	                    xtype:'textfield',
    	                    fieldLabel: 'No Order',
    	                    name: 'no_order',
    	                    anchor:'95%'
    	                }]
    	            },{
    	                columnWidth:.5,
    	                layout: 'form',
    	                border:false,
    	                items: [{
    						fieldLabel 		: 'Supplier',
    						xtype	   		: 'combo',	
    						store			: supplierStore,
    						typeAhead		: true,
    						editable		: true,
    						mode			: 'local',
    						triggerAction	: 'all',
    						selectOnFocus	: true,
    						displayField	: 'name',
                			valueField		: 'id', 
                			name	   		: 'supplier_id',	
                			hiddenName 		: 'supplier_id',
                			anchor:'95%'
    	                },{
    	                    xtype:'textfield',
    	                    fieldLabel: 'No Container',
    	                    name: 'no_truck',
    	                    anchor:'95%'
    	                }
    	                ]
    	            }]
    	        },{
    	            xtype:'panel',
    	            plain:true,
    	            deferredRender: false,
    	            defaults:{bodyStyle:'padding:10px'},
    	            items:[ MaterialinGrid]
    	        }],
    	        buttons: [{
    	            text: 'Save',
                	formBind : true,
                	iconCls: 'icon-save',
    	            handler  : function(){
    	              var dstore = MaterialinGrid.store;
					  var data_array = [];
					  dstore .each(function(dstore ){
						        data_array.push(dstore .data);
					  });
					  data_array = Ext.util.JSON.encode(data_array);
					 		
    	        	frmPanel.getForm().submit({
    	        	
    	                    method    : 'POST',
    	                    waitTitle : 'Processing',
    	                    waitMsg   : 'Please Wait',
    	                    params	  : {material:data_array },
    	                    success   : function (form, action) {
    	                    	Ext.Msg.alert('Sukses!', action.result.message);
    	                    	//store.reload();
    	                    	//addAnggotaWin.close();
    	                    	MaterialinGrid.store.load();
    	                    	form.reset();
    	                    },
    	                    failure   : function (form, action) {
    	                        if (action.failureType === 'server') {
    	                            //obj = Ext.util.JSON.decode(action.response.responseText).data;
    	                            Ext.Msg.alert('Process Failed!', action.result.error);
    	                        } else {
    	                            //obj = Ext.util.JSON.decode(action.response.responseText);
    	                            Ext.Msg.alert('Warning!', action.result.error);
    	                        }
    	                    }
    	                });
    	              
    	               
    	                //MaterialinGrid.store.save();
    	                
    	            }
    	        }]
    	        
    	    });
    	    
            win = desktop.createWindow({
                id: 'materialin-win',
                title:'Materil In',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [frmPanel]
            });
        }
        win.show();
    },
    
    createDataWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('supplier-win');
        if(!win){
        	var MaterialinDataGrid = new App.materialindata.Grid();
            win = desktop.createWindow({
                id: 'datamaterialin-win',
                title:'Data Material In',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [MaterialinDataGrid]
            });
        }
        win.show();
    }
});

MyDesktop.ReportMenuModule = Ext.extend(Ext.app.Module, {
    init : function(){
        this.launcher = {
            text: 'Report',
            iconCls: 'bogus',
            handler: function() {
				return false;
			},
            menu: {
                items:[{
                    text: 'Daily Report',
                    iconCls:'bogus',
                    handler : this.locationReportWindow,
                    scope: this,
                    windowId: 'locationreport-win'
                    },{
                    text: 'DetailReport',
                    iconCls:'bogus',
                    handler : this.detailReportWindow,
                    scope: this,
                    windowId: 'detailreport-win'
                    },{
                    text: 'Monthly Report',
                    iconCls:'bogus',
                    handler : this.monthlyReportWindow,
                    scope: this,
                    windowId: 'monthlyreport-win'
                    }]
            }
        }
    },
    
    locationReportWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('locationreport-win');
        if(!win){
        	var DailyReport = new App.dailyreport.Grid();
 	        var exportButton = new Ext.ux.Exporter.Button({
	          component: DailyReport,
	          text     : "Excel"
	        });
	        
	        DailyReport.getTopToolbar().add(exportButton);
            win = desktop.createWindow({
                id: 'locationreport-win',
                title:'Daily Report',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [DailyReport]
            });
        }
        win.show();
    },
    
    detailReportWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('detailreport-win');
        if(!win){
        	var DetailReportGrid = new App.detailreport.Grid();
            win = desktop.createWindow({
                id: 'detailreport-win',
                title:'Detail Report',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [DetailReportGrid]
            });
        }
        win.show();
    },
    monthlyReportWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('monthlyreport-win');
        if(!win){
        	var MonthlyReportGrid = new App.monthlyreport.Grid();
            win = desktop.createWindow({
                id: 'monthlyreport-win',
                title:'Detail Report',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [MonthlyReportGrid]
            });
        }
        win.show();
    }
});


MyDesktop.BogusMenuModule = Ext.extend(MyDesktop.BogusModule, {
    init : function(){
        this.launcher = {
            text: 'Bogus Submenu',
            iconCls: 'bogus',
            handler: function() {
				return false;
			},
            menu: {
                items:[{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                }]
            }
        }
    }
});


MyDesktop.DailyreportWindow = Ext.extend(Ext.app.Module, {
    id:'grid-dailyreport',
    init : function(){
        this.launcher = {
            text: 'Daily Report',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('grid-dailyreport');
        if(!win){
        	var DailyReport = new App.dailyreport.Grid();
        	
	        var exportButton = new Ext.ux.Exporter.Button({
	          component: DailyReport,
	          text     : "Download as .xls"
	        });
	        
	        DailyReport.getTopToolbar().add(exportButton);
	        
            win = desktop.createWindow({
                id: 'grid-dailyreport',
                title:'Daily Report',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [DailyReport]
            });
        }
        win.show();
    }
});

//location
MyDesktop.UserWindow = Ext.extend(Ext.app.Module, {
    init : function(){
        this.launcher = {
            text: 'Admin',
            iconCls: 'bogus',
            handler: function() {
				return false;
			},
            menu: {
                items:[{
                    text: 'Add User',
                    iconCls:'bogus',
                    handler : this.createFormWindow,
                    scope: this,
                    windowId: 'formuser-win'
                    },{
                    text: 'Daftar User',
                    iconCls:'bogus',
                    handler : this.createDataWindow,
                    scope: this,
                    windowId: 'userlist-win'
                    }]
               }
            }
    },
    
	createFormWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('formuser-win');
        var UserGrid = new App.user.Grid();
        if(!win){
        	//var MaterialinGrid = new App.materialin.Grid();
	    	

            var frmPanel = new Ext.FormPanel({
            	id			: 'user-form',
    	   	 	url         : '<?php echo URL::base()?>user/save',
    	        labelAlign	: 'top',
    	        bodyStyle	: 'padding:5px',
    	        width		: 350,
    	        items: [{
    	                    xtype:'textfield',
    	                    fieldLabel: 'Username',
    	                    name: 'username',
    	                    anchor:'100%'
    	                },{
    	                    xtype:'textfield',
    	                    fieldLabel: 'E-Mail',
    	                    name: 'email',
    	                    vtype:'email',
    	                    anchor:'100%'
    	                },{
    	                    xtype:'textfield',
    	                    fieldLabel: 'Password',
    	                    inputType: 'password',
    	                    name: 'password',
    	                    anchor:'100%'
    	                 },{
    	                    xtype:'textfield',
    	                    fieldLabel: 'Konfirm Password',
    	                    name: 'password_confirm',
    	                    inputType: 'password',
    	                    anchor:'100%'
    	                 },{
                                xtype:          'combo',
                                mode:           'local',
                                value:          'user',
                                triggerAction:  'all',
                                forceSelection: true,
                                editable:       false,
                                fieldLabel:     'Type User',
                                name:           'type',
                                hiddenName:     'type',
                                displayField:   'name',
                                valueField:     'value',
                                store:          new Ext.data.JsonStore({
                                    fields : ['name', 'value'],
                                    data   : [
                                        {name : 'User',   value: '1'},
                                        {name : 'Admin',  value: '2'}
                                    ]
                                })
    	        }],
    	        buttons: [{
    	            text: 'Save',
                	formBind : true,
                	iconCls: 'icon-save',
    	            handler  : function(){
					 		
    	        	frmPanel.getForm().submit({
    	        	
    	                    method    : 'POST',
    	                    waitTitle : 'Processing',
    	                    waitMsg   : 'Please Wait',
    	                    success   : function (form, action) {
    	                    	Ext.Msg.alert('Sukses!', action.result.message);
    	                    	//MaterialoutGrid.store.removeAll();
    	                    	//addAnggotaWin.close();
    	                    	UserGrid.store.load();
    	                    	form.reset();
    	                    },
    	                    failure   : function (form, action) {
    	                        if (action.failureType === 'server') {
    	                            //obj = Ext.util.JSON.decode(action.response.responseText).data;
    	                            Ext.Msg.alert('Process Failed!', action.result.message);
    	                        } else {
    	                            //obj = Ext.util.JSON.decode(action.response.responseText);
    	                            Ext.Msg.alert('Warning!', action.result.message);
    	                        }
    	                    }
    	                });
    	              
    	               
    	                //MaterialinGrid.store.save();
    	                
    	            }
    	        },{
       	            text: 'Cancel',
                	formBind : true,
                	iconCls: 'icon-reset', 
                	handler: function(){
                		frmPanel.getForm().reset();
                	}	        
    	        }]
    	        
    	    });
    	    
            win = desktop.createWindow({
                id: 'formuser-win',
                title:'Add User',
                width:270,
                height:320,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [frmPanel]
            });
        }
        win.show();
    },

    createDataWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('user-win');
        if(!win){
        	var UserGrid = new App.user.Grid();
            win = desktop.createWindow({
                id: 'user-win',
                title:'User Managemen',
                width:550,
                height:650,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [UserGrid]
            });
        }
        win.show();
    }
});


MyDesktop.MaterialoutMenuModule = Ext.extend(Ext.app.Module, {
    init : function(){
        this.launcher = {
            text: 'Material Out',
            iconCls: 'bogus',
            handler: function() {
				return false;
			},
            menu: {
                items:[{
                    text: 'Form Material Out',
                    iconCls:'bogus',
                    handler : this.createFormWindow,
                    scope: this,
                    windowId: 'materialin-win'
                    },{
                    text: 'Data Material Out',
                    iconCls:'bogus',
                    handler : this.createDataWindow,
                    scope: this,
                    windowId: 'supplier-win'
                    }]
            }
        }
    },
    
	createFormWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('materialout-win');
        var MaterialoutGrid = new App.materialout.Grid({id:0});
        if(!win){
        	//var MaterialinGrid = new App.materialin.Grid();
            
            var locationStore = new Ext.data.JsonStore({
                url           : '<?php echo URL::base()?>location/view',
                root          : 'location',
                totalProperty : 'total',
                id            : 'id',
                fields        : ['id', 'name'],
                remoteSort    : true,
                autoload      : true
            });

            locationStore.load();   

            var frmPanel = new Ext.FormPanel({
    	   	 	url         : '<?php echo URL::base()?>materialout/save',
    	        labelAlign: 'top',
    	        bodyStyle:'padding:5px',
    	        width:740,
    	        items: [{
    	            layout:'column',
    	            border:false,
    	            items:[{
    	                columnWidth:.5,
    	                layout: 'form',
    	                border:false,
    	                items: [{
    	                    xtype:'datefield',
    	                    fieldLabel: 'Tanggal',
    	                    name: 'tgl',
    	                    anchor:'95%',
    	                    format: 'd/m/Y',
    	                    value: new Date()
    	                },{
    	                    xtype:'textfield',
    	                    fieldLabel: 'No Order',
    	                    name: 'no_order',
    	                    anchor:'95%'
    	                },{
    	                    xtype:'textfield',
    	                    fieldLabel: 'No Charge',
    	                    name: 'no_charge',
    	                    anchor:'95%'
    	                }]
    	            }]
    	        },{
    	            xtype:'panel',
    	            plain:true,
    	            deferredRender: false,
    	            defaults:{bodyStyle:'padding:10px'},
    	            items:[ MaterialoutGrid]
    	        }],
    	        buttons: [{
    	            text: 'Save',
                	formBind : true,
                	iconCls: 'icon-save',
    	            handler  : function(){
    	              var dstore = MaterialoutGrid.store;
					  var data_array = [];
					  dstore .each(function(dstore ){
						        data_array.push(dstore .data);
					  });
					  data_array = Ext.util.JSON.encode(data_array);
					 		
    	        	frmPanel.getForm().submit({
    	        	
    	                    method    : 'POST',
    	                    waitTitle : 'Processing',
    	                    waitMsg   : 'Please Wait',
    	                    params	  : {material:data_array },
    	                    success   : function (form, action) {
    	                    	Ext.Msg.alert('Sukses!', action.result.message);
    	                    	//MaterialoutGrid.store.removeAll();
    	                    	//addAnggotaWin.close();
    	                    	MaterialoutGrid.store.load();
    	                    	form.reset();
    	                    },
    	                    failure   : function (form, action) {
    	                        if (action.failureType === 'server') {
    	                            //obj = Ext.util.JSON.decode(action.response.responseText).data;
    	                            Ext.Msg.alert('Process Failed!', action.result.error);
    	                        } else {
    	                            //obj = Ext.util.JSON.decode(action.response.responseText);
    	                            Ext.Msg.alert('Warning!', action.result.error);
    	                        }
    	                    }
    	                });
    	              
    	               
    	                //MaterialinGrid.store.save();
    	                
    	            }
    	        }]
    	        
    	    });
    	    
            win = desktop.createWindow({
                id: 'materialout-win',
                title:'Material Out',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [frmPanel]
            });
        }
        win.show();
    },
    
    createDataWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('datamaterialout-win');
        if(!win){
        	var MaterialoutDataGrid = new App.materialoutdata.Grid({
        	id: 0
        });
            win = desktop.createWindow({
                id: 'datamaterialout-win',
                title:'Data Material Out',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items: [MaterialoutDataGrid]
            });
        }
        win.show();
    }
});


// Array data for the grid
Ext.grid.dummyData = [
    ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
    ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
    ['American Express Company',52.55,0.01,0.02,'9/1 12:00am'],
    ['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am'],
    ['AT&T Inc.',31.61,-0.48,-1.54,'9/1 12:00am'],
    ['Caterpillar Inc.',67.27,0.92,1.39,'9/1 12:00am'],
    ['Citigroup, Inc.',49.37,0.02,0.04,'9/1 12:00am'],
    ['Exxon Mobil Corp',68.1,-0.43,-0.64,'9/1 12:00am'],
    ['General Electric Company',34.14,-0.08,-0.23,'9/1 12:00am'],
    ['General Motors Corporation',30.27,1.09,3.74,'9/1 12:00am'],
    ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am'],
    ['Honeywell Intl Inc',38.77,0.05,0.13,'9/1 12:00am'],
    ['Intel Corporation',19.88,0.31,1.58,'9/1 12:00am'],
    ['Johnson & Johnson',64.72,0.06,0.09,'9/1 12:00am'],
    ['Merck & Co., Inc.',40.96,0.41,1.01,'9/1 12:00am'],
    ['Microsoft Corporation',25.84,0.14,0.54,'9/1 12:00am'],
    ['The Coca-Cola Company',45.07,0.26,0.58,'9/1 12:00am'],
    ['The Procter & Gamble Company',61.91,0.01,0.02,'9/1 12:00am'],
    ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am'],
    ['Walt Disney Company (The) (Holding Company)',29.89,0.24,0.81,'9/1 12:00am']
];